package com.ouc.eddyAlgorithm.service.impl;

import com.ouc.eddyAlgorithm.domain.VgEddy;
import com.ouc.eddyAlgorithm.mapper.Vga4b3Mapper;
import com.ouc.eddyAlgorithm.service.VgA3B4Service;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VgA3B4ServiceImpl implements VgA3B4Service {

  @Autowired
  private Vga4b3Mapper vga4b3Mapper;

  @Autowired
  SqlSessionFactory sqlSessionFactory;

  @Override
  public List<VgEddy> findVgEddyByDateAndLevel(String date, Integer level) {
    return vga4b3Mapper.findByDateAndLevel(date, level);
  }


  @Override
  public List<VgEddy> findByEddyIdAndDateAndLevel(Integer eddyId, String date, Integer level) {
    return vga4b3Mapper.findByEddyIdAndDateAndLevel(eddyId, date, level);
  }

  @Override
  public void insertByBach(List<VgEddy> vgEddyList) {
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
    //	自动提交设置为false
    Vga4b3Mapper mapper = sqlSession.getMapper(Vga4b3Mapper.class);
    for (VgEddy eddySet : vgEddyList) {
      mapper.insert(eddySet);
    }

    sqlSession.commit();
    sqlSession.clearCache();
    sqlSession.close();
  }

}
